package com.sz.ruichar.utils.system;


import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.FileUtils;

/**
 * Created by liyang on 2017/8/4.
 */
public class FileUtil {

    /**
     * 读取文件内容
     */
    public static String readResourceFile(String resourcePath) {

        // 获取resource中文件的fileName
        URL url = FileUtil.class.getClassLoader().getResource(resourcePath);
        String fileName = url.getPath();

        // 读取文件
        String content = null;
        try {
            content = FileUtils.readFileToString(new File(fileName), "UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }

        return content;
    }

    //用于对邮件模板内容替换进行测试
    public static void main(String args[]){
        // 加载模板
        String template1 = FileUtil.readResourceFile("emailTemplate/template_alarm.txt");
        String template = null;
        // 替换模板变量
        template = template.replace("#{personType}", "借款人");
        template = template.replace("#{name}", "李阳");

        String phone = "15019210890";
        phone = phone.substring(0,3) + "****" + phone.substring(7,11);
        System.out.println(phone);
        template = template.replace("#{phone}", phone);

        String content = template.replace("\r\n", "<br/>");
        System.out.println(content);
    }


}
